use std::sync::OnceLock;

use serde::Deserialize;
use tools::global_defin::config::load_config;

use crate::business::called_rule::OneCalledRule;


///业务逻辑的配置文件相关
#[derive(Debug, Deserialize)]
pub struct BusinessConfig {
	pub platform_id: i32,
	pub default_wait_bell_path: &'static str,
	pub not_found_node_bell_path: &'static str,
	pub not_money_bell_path: &'static str,
	pub not_allow_caller_bell_path: &'static str,
	pub leave_message_bell_path: &'static str,
	pub phone_busy_bell_path: &'static str,
	pub invalid_bell_path: &'static str,
	pub seat_warm_caller_bell_path: &'static str,
	pub seat_warm_called_bell_path: &'static str,
	pub not_phone_node: &'static str,
	pub pause_bell_path: &'static str,
	pub caller_rule: u8,
	pub specific_caller_num: &'static str,
	pub caller_not_in_white_list: &'static str,
	pub caller_in_black_list: &'static str,
	pub area_refuse: &'static str,
	pub time_refuse: &'static str,
	///是否需要接通才能播放声音,如果此值为true,则会在放音前进行接通操作
	/// 否则放预接通信号,再放音
	pub play_need_answer: bool,
	pub called_rules: Vec<OneCalledRule>,
	// ///拨测获取的间隔时间，秒为单位
	// pub dial_test_interval: u16,
	// pub call_out_channel_name: &'static str,
	// pub not_found_config_path: &'static str,
}

/**
 * 读配置文件
 */
#[inline]
pub fn business_config() -> &'static BusinessConfig {
	static CONFIG: OnceLock<BusinessConfig> = OnceLock::new();
	// 尝试获取或初始化配置信息
	CONFIG.get_or_init(|| load_config("./config/business.json"))
}

#[inline]
pub fn platform_id() -> i32 {
	business_config().platform_id
}
